﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Arles.src.controller;
using ArlesInterfaces.Editor;
using Arles.src.controller.Commands;

namespace Arles.src.view
{
    public partial class FScene : DockContent
    {
        public TreeView SceneTree
        {
            get { return tvScene; }
        }


        public FScene()
        {
            InitializeComponent();
        }

        private void tvScene_DoubleClick(object sender, EventArgs e)
        {
            if (tvScene.SelectedNode != null)
            {
                ObjectType type = (ObjectType)Enum.Parse(typeof(ObjectType), tvScene.SelectedNode.Name);
                Editor.Instance.MainForm.Properties.SelectedObject =
                    Editor.Instance.Scene.GetObject(type, tvScene.SelectedNode.ImageIndex);

                Editor.Instance.MainForm.PropertyShow();
            }
        }

        private void addSkydomeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Editor.Instance.Scene.GetObject(ObjectType.Skydome) == null)
            {
                SkydomeCommand command = new SkydomeCommand(Editor.Instance, true);
                Editor.Instance.Invoker.ExecuteCommand(command);
            }
            else
            {
                MessageBox.Show("there already exists a Skydome in the scene");
            }
        }

        private void addTerrainToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Editor.Instance.Scene.GetObject(ObjectType.Terrain) == null)
            {
              HeightmapImportCommand command = new HeightmapImportCommand(Editor.Instance, "");
              Editor.Instance.Invoker.ExecuteCommand(command);
            }
            else
            {
              MessageBox.Show("there already exists a Terrain in the scene");
            }
        }

        private void tvScene_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Delete && tvScene.SelectedNode != null)
            {
                ObjectType type = (ObjectType)Enum.Parse(typeof(ObjectType), tvScene.SelectedNode.Name);
                switch (type)
                {
                    case ObjectType.Skydome:
                        SkydomeCommand command = new SkydomeCommand(Editor.Instance, false);
                        Editor.Instance.Invoker.ExecuteCommand(command);
                        break;
                    case ObjectType.Water:
                        break;
                    case ObjectType.Terrain:
                        break;
                    case ObjectType.Objects:
                        break;
                    case ObjectType.Vegetation:
                        break;
                    default:
                        break;
                }

                Editor.Instance.MainForm.Properties.SelectedObject = null;
            }
        }

    }
}
